<template>
  <div class="app-container">
    <!-- 组别 -->
    <el-row>
      <el-col :span="2"><div>组别设置</div></el-col>
      <el-col :span="18"
        ><el-button class="button-new-tag" size="small" @click="showInput"
          >+ 新增组别</el-button
        ></el-col
      >
    </el-row>

    <!-- 轮播图 -->
    <el-row>
      <el-col :span="2"><div>轮播图设置</div></el-col>
      <el-col :span="18"
        ><!-- 放置上传图片 -->
        <image-upload :limit="5" v-model="form.image"></image-upload
      ></el-col>
    </el-row>

    <!-- 官方手册 -->
    <el-row>
      <el-col :span="2"><div>官方手册</div></el-col>
      <el-col :span="18"
        ><el-button
          class="button-new-tag"
          size="small"
          @click="handleSetOfficialManual"
          >+ 配置富文本</el-button
        ></el-col
      >
    </el-row>

    <!-- 竞赛规程 -->
    <el-row>
      <el-col :span="2"><div>竞赛规程</div></el-col>
      <el-col :span="18"
        ><el-button
          class="button-new-tag"
          size="small"
          @click="handleSetCompetitionRules"
          >+ 配置富文本</el-button
        ></el-col
      >
    </el-row>

    <!-- 赛事新闻 -->
    <el-row>
      <el-col :span="2"><div>赛事新闻</div></el-col>
      <el-col :span="9"
        ><el-button
          class="button-new-tag"
          size="small"
          @click="handleSetEventNews"
          >+ 配置富文本</el-button
        ></el-col
      >
    </el-row>

    <!-- 动态标签 -->
    <el-row>
      <el-col :span="2"><div>标签配置</div></el-col>
      <el-col :span="1.5"
        ><el-button class="button-new-tag" size="small" @click="showInput"
          >+ 新增标签</el-button
        ></el-col
      >
      <el-col :span="2"
        ><el-button
          class="button-new-tag"
          size="small"
          @click="handleSetDynamicTag"
          >+ 配置富文本</el-button
        ></el-col
      >
    </el-row>

    <!-- 编辑组别dialog -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      append-to-body
      @close="reset"
    >
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="组别">
          <el-input
            v-model="form.inputValue"
            placeholder="请输入组别名称"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fetchData: {
        // 组别
        dynamicTags: [],
      },
      inputValue: undefined,
      // 编辑组别
      open: false,
      form: {},
      // 弹出层标题
      title: undefined,
    };
  },
  methods: {
    showInput() {
      this.open = true;
      this.title = "新增组别";
    },
    handleInputConfirm() {
      let inputValue = this.inputValue;
      if (inputValue) {
        // 测试
        this.fetchData.dynamicTags.push(inputValue);

        // 调用新建组别接口
        // 获取组别接口
      }
      this.inputValue = "";
    },
    handleUpdate(row) {
      this.open = true;
      this.title = "编辑组别";
      console.log(row);
      this.form.inputValue = row;
    },
    handleSetDynamicTag() {
      this.$router.push("/rich/manager/index");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    reset() {
      this.fetchData.dynamicTags = [];
      this.resetForm("form");
    },
    // 提交按钮
    submitForm() {
      this.open = false;
    },
  },
};
</script>

<style scoped lang="scss">
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}

.grid-add {
  border-radius: 4px;
  height: 50px;
  margin-top: 20px;
  width: 100%;
  background: #d3dce6;
  text-align: center;
  display: flex;
  justify-content: center;
}

.el-row {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}

.bg-purple {
  background: #d3dce6;
}

.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  width: 100%;
  margin-top: 20px;
}
</style>
